detailController.$inject = ['$scope', '$stateParams', '$http', '$location'];
var io = require('socket.io-client');
const socket = io('http://zha-ita077-w7:3001');

function detailController($scope, $stateParams, $http, $location) {
    $scope.id = $stateParams.id;
    var vm = this;
    $http({
        url: "/api/admin/manage/merchants/id/" + $scope.id,
        method: 'GET',
    }).then(function(response) {
        vm.merchant = response.data[0];
    })
    vm.passAudit = function(id) {
        $http({
            url: "/api/admin/manage/merchants/white",
            method: 'PUT',
            data: {
                'id': id
            }
        }).then(function(response) {
            if (response.data.nModified == 1) {
                socket.emit('notify', { merchantId: vm.merchant._id, message: "You have pass the verfy", code: 2, status: "white_list" });
                vm.merchant.mStatus = 'white_list'
            }

        })
    }

    vm.rejectAudit = function(id) {
        console.log(vm.rejectReason);
        $http({
            url: "/api/admin/manage/merchants/reject",
            method: 'PUT',
            data: {
                'id': id,
                'reason': vm.rejectReason
            }
        }).then(function(response) {
            if (response.data.ok == 1); {
                socket.emit('notify', { merchantId: vm.merchant._id, message: vm.rejectReason, code: 2, status: "reject" });
                vm.merchant.mStatus = 'reject'
            }

        })
    }

    vm.checkReason = function(rejectReason) {
        if (rejectReason != undefined)
            return false;
        else
            return true;
    }
}

module.exports = detailController;